//工厂生产模式
#include<iostream>
#include<memory>
#include<string>
using namespace std;

class Fruit
{
public:
    Fruit(){}
    virtual void show()=0;
};
class Apple:public Fruit
{
public:
    Apple(){}
    void show() override
    {
        cout<<"这是一个苹果"<<endl;
    }
};
class Banana:public Fruit
{
public:
    Banana(){}
    void show() override
    {
        cout<<"这是一个香蕉"<<endl;
    }
};
class FruitFactor
{
public:
    virtual shared_ptr<Fruit> create()=0;
};
class AppleFactor:public FruitFactor
{
public:
    shared_ptr<Fruit> create() override
    {
        return make_shared<Apple>();
    }
};
class BananaFactor:public FruitFactor
{
public:
    shared_ptr<Fruit> create() override
    {
        return make_shared<Banana>();
    }
};
int main()
{
    shared_ptr<FruitFactor> sp(new AppleFactor());
    shared_ptr<Fruit> spfruit=sp->create();
    spfruit->show();
    sp.reset(new BananaFactor());
    spfruit=sp->create();
    spfruit->show();
    return 0;
}